//
//  MainTabBarController.m
//  ExcellentCease
//
//  Created by UNOHACHA on 16/12/6.
//  Copyright © 2016年 iMacOne. All rights reserved.
//

#import "MainTabBarController.h"


#import "DHNavigationController.h"

#import "Header.h"

//#import "LoginViewController.h"


#import "HomeViewController.h"
#import "FindViewController.h"
//#import "YRUNViewController.h"

#import "CircleHomeViewController.h"
#import "SelfHomeViewController.h"

#import "UINavigationController+FDFullscreenPopGesture.h"

@interface MainTabBarController ()<UITabBarControllerDelegate,UITabBarDelegate>

@end

@implementation MainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    
    self.delegate=self;

    [self setTabBarTitleAttributesStyle];
    

    HomeViewController *homeVC = [[HomeViewController alloc]init];
    
    FindViewController *shopVC = [FindViewController new];
    
//    YRUNViewController *DiscVC = [YRUNViewController new];

    CircleHomeViewController *CircleVC = [CircleHomeViewController new];

    SelfHomeViewController *mySelfVC = [SelfHomeViewController new];
    
    [self setChildVC:homeVC title:@"首页" image:@"home" selectImgage:@"home-main"];
    [self setChildVC:shopVC title:@"发现" image:@"find" selectImgage:@"find-main"];
    
//    [self setChildVC:DiscVC title:@"Y·RUN" image:@"灰色" selectImgage:@"黑色"];
        
    [self setChildVC:CircleVC title:@"圈子" image:@"circle" selectImgage:@"circle-main"];
    [self setChildVC:mySelfVC title:@"我的" image:@"mine" selectImgage:@"mine-main"];
    
    
 
//        [self addChildViewController:homeVC image:@"ic_home_nor" selectedImage:@"ic_home_li" title:@"首页"];
//
//        [self addChildViewController:shopVC image:@"ic_gouwuche_nor" selectedImage:@"ic_gouwuche_li" title:@"发现"];
//
//        [self addChildViewController:DiscVC image:@"ic_faxian_nor" selectedImage:@"ic_faxian_li" title:@"Y·RUN"];
//
//        [self addChildViewController:CircleVC image:@"ic_mine_nor" selectedImage:@"ic_mine_li" title:@"圈子"];
//
//        [self addChildViewController:mySelfVC image:@"ic_mine_nor" selectedImage:@"ic_mine_li" title:@"我的"];
    
}

#pragma mark - 设置tabbar上面的字 setTitleTextAttributes
- (void)setTabBarTitleAttributesStyle
{
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    //通常字体大小
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    //通常字体颜色
    attrs[NSForegroundColorAttributeName] = UIColorFromRGB(0x666666);
    
    NSMutableDictionary *selectAttrs = [NSMutableDictionary dictionary];
    //选中字体大小
    selectAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    //选中字体颜色
    selectAttrs[NSForegroundColorAttributeName] = UIColorFromRGB(0x333333);// HOME_COLOR;
    
    
    
    //UI_APPEARANCE_SELECTOR 外观
    UITabBarItem *item = [UITabBarItem appearance];
    //tabbar通常字体样式
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    //tabbar选中字体样式
    [item setTitleTextAttributes:selectAttrs forState:UIControlStateSelected];
}

//#pragma mark - 导航子视图封装
- (void)setChildVC:(UIViewController *)childController title:(NSString *)title image:(NSString *)image selectImgage:(NSString *)selectImage{

   // 导航
    DHNavigationController *mainNav = [[DHNavigationController alloc]initWithRootViewController:childController];
//    mainNav.navigationBarHidden=YES;
    
    
    childController.fd_prefersNavigationBarHidden = YES;
    
    //子视图显示在UITabbarController上显示的tabbar标题
    mainNav.tabBarItem.title = title;
    //子视图显示在UITabbarController上未选中tabbar的图片
    mainNav.tabBarItem.image = [UIImage imageNamed:image];
    //子视图显示在UITabbarController上选中tabbar的图片
    mainNav.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    mainNav.view.backgroundColor = [UIColor whiteColor];
    
//    childController.navigationItem.title = title;
    
    [self addChildViewController:mainNav];
 
}


//- (void)addChildViewController:(UIViewController *)childController image:(NSString *)image selectedImage:(NSString *)selectedImage title:(NSString *)title {
//
//      //子视图显示在UITabbarController上显示的tabbar标题
//    childController.tabBarItem.title = title;
//   //子视图显示在UITabbarController上未选中tabbar的图片
//    childController.tabBarItem.image = [UIImage imageNamed:image];
//    //子视图显示在UITabbarController上选中tabbar的图片
//    childController.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    
//    childController.navigationItem.title = title;
//    
//    //字体
////    [childController.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:12.5]} forState:UIControlStateNormal];
//
//    
//    DHNavigationController * mainNav = [[DHNavigationController alloc] initWithRootViewController:childController];
//    
//    [self addChildViewController:mainNav];
//    
//    
////    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:childController];
////    nav.navigationBarHidden=YES;
//////    添加
////    [self addChildViewController:nav];
//
////
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
